<?php

namespace App\Model;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

/**
 * Class UserTemplate
 *
 * @package App
 * @method static \Illuminate\Database\Query\Builder|$this create(array $attributes = [])
 * @method static \Illuminate\Database\Query\Builder|$this find($id, $columns = ['*'])
 * @method static \Illuminate\Database\Query\Builder|$this findOrFail($id, $columns = ['*'])
 * @method static \Illuminate\Database\Query\Builder|$this where($column, $operator = null, $value = null, $boolean = 'and')
 * @mixin \Eloquent
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserTemplate newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserTemplate newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserTemplate query()
 * @property int $id
 * @property int $user_id 用户id
 * @property int $template_id 模板id
 * @property string|null $cover 封面
 * @property string $title 模板名称
 * @property string $content 内容
 * @property int $is_default 是否默认1默认0 不是默认
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property int $popularity 人气
 * @property int|null $cate category->id
 * @property string $components 自定义组件
 * @property int $type 1定制模板2自定义模板
 * @property string $background 背景颜色
 * @property int $is_clone 是否允许被克隆
 * @property float $clone_price 克隆价格
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserTemplate whereBackground($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserTemplate whereCate($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserTemplate whereClonePrice($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserTemplate whereComponents($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserTemplate whereContent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserTemplate whereCover($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserTemplate whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserTemplate whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserTemplate whereIsClone($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserTemplate whereIsDefault($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserTemplate wherePopularity($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserTemplate whereTemplateId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserTemplate whereTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserTemplate whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserTemplate whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserTemplate whereUserId($value)
 * @property int $share 分享量
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserTemplate whereShare($value)
 */
class UserTemplate extends Model
{
    protected $table = 'personal_page_template_user';

    public static function popularity($user_id)
    {
        $count = DB::table('personal_page_template_popularity')->where('target_user_id', $user_id)->count();
        return $count?:0;
    }

    public static function popularityToDay($user_id)
    {
        $count = DB::table('personal_page_template_popularity')->where('target_user_id', $user_id)->whereDate('created_at', Carbon::today()->toDateString())->count();
        return $count?:0;
    }
}
